package bank.model.vo;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Date;

/**
 * @author k.rudy
 *
 */
public abstract class Document {
	private Date creationDate;
	private Employee employee;
	private int id;
	private static int nextId = 0;
	private ArrayList<String> lines;
		

	public Document(Employee employee) {
		this.employee = employee;
		creationDate = new Date();
		lines = new ArrayList<String>();
		id = nextId;
	    nextId++;
	}
	
	public Document(int id, Employee employee) {
		this.employee = employee;
		creationDate = new Date();
		lines = new ArrayList<String>();
		this.id = id;
	    nextId = id++;
	}
	
	public Date getCreationDate() {
		return creationDate;
	}

    public Employee getEmployee() {
    	return employee; 
    }
    
    public int getId(){
    	return id;
    }
    
    public void saveToFile(String fileName){
    	try {
    		File file = new File(fileName);
    		FileWriter writer = new FileWriter(file);
        	generateLines();
        	for (String line: lines) {
        		writer.append(line);
        	}        	
        	writer.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
    }
    
    protected void addLine(String newLine) {
    	lines.add(newLine);
    }
    
    public ArrayList<String> getLines() {
    	return lines;
    }
    
    protected abstract void generateLines();
}
